<template>
  <div class="app">
    <div class="search-bar">
      <el-form :model="searchData" label-width="70px">
        <el-row :gutter="10">
          <el-col :span="8">
            <el-form-item label="稽核日期">
              <el-date-picker
                size="medium"
                v-model="searchData.date"
                type="daterange"
                range-separator="—"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                format="yyyy 年 MM 月 dd 日"
                value-format="yyyy-MM-dd"
                class="select"
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="任务状态">
              <el-select v-model="searchData.status" placeholder="请选择" size="medium" class="select">
                <el-option label="稽核任务正常执行" value="1"></el-option>
                <el-option label="稽核任务出现错误" value="0"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <div style="margin-top: 3px">
              <el-button type="primary" size="small" @click="handleSearch">查询</el-button>
              <el-button size="small" @click="handleClear">重置</el-button>
            </div>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div ref="ref2" class="table-box">
      <tableComponent
        class="table"
        :height="height"
        :data="tableData || []"
        :columns="tableColumns"
        @change="tablePage"
        :table-option="tableOption"
        :page-option="searchData.page"
        :total="total"
      >
        <template scope="scope">
          <el-button :disabled="scope.scope.row.status==='0'" @click="handleSee(scope.scope.row)" type="text" size="mini">预览</el-button>
        </template>
      </tableComponent>
    </div>
  </div>
</template>

<script>
import tableComponent from '@/components/Table/table'
import { tableColumns } from './index.js'
import { queryCheckTask } from '@/api/modules/checkTask.js'
export default {
  components: {
    tableComponent
  },
  data() {
    return {
      searchData: {
        status: '',
        page: {
          pageNum: 1,
          pageSize: 10
        }
      },
      height: null,
      tableColumns,
      tableData: [],
      tableOption: {
        isShowOperate: true,
        operateWidth: '60px'
      },
      total: 0
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.height = this.$refs.ref2.offsetHeight
    })
    window.onresize = () => {
      this.height = this.$refs.ref2.offsetHeight
    }
    this.initData()
  },
  destroyed(){
    window.onresize = null
  },
  methods: {
    initData() {
      queryCheckTask(this.searchData).then(res => {
        if (res.data.code === '200') {
          this.tableData = res.data.data.list
          this.total = res.data.data.total
        } else {
          this.$message.error(res.data.message)
        }
      })
    },
    // 查询
    handleSearch() {
      this.initData(this.searchData)
    },
    // 分页
    tablePage(val) {
      this.searchData.page = val
      this.initData(this.searchData)
    },
    // 重置
    handleClear() {
      this.searchData.status = ''
      this.searchData.result = ''
    },
    handleSee(row) {
      const data = {
        auditId: row.auditId
      }
      this.$router.push({ path: '/checkReport', query: data })
    }
  }
}
</script>

<style lang="less" scoped>
  .app {
    height: 100%;
    .search-bar {
      width: calc(100% - 60px);
      background-color: #ffffff;
      margin-bottom: 10px;
      padding: 10px 30px;
      height: 40px;
    }
    .table-box {
      width: 100%;
      height: calc(100vh - 200px);
      .table {
        height: 100%;
      }
    }
    .select {
      width: 100%;
    }
  }
</style>